#!/usr/bin/env python

# Outputs to stdout

import os, sys
from optparse import OptionParser

if __name__ == "__main__":
    parser = OptionParser(usage = "%prog <input extension> <output extension>")
    parser.add_option("-d", "--datadir", type = "string", dest = "datadir", default = "data", help = "The directory of data files")
    parser.add_option("-t", "--timelimit", type = "int", dest = "timelimit", default = 10, help = "Time limit for each test case")
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.print_usage()
        exit(-1)

    input_ext = args[0]
    output_ext = args[1]

    input_files = []
    output_files = []

    for root, dirs, files in os.walk(options.datadir):
        for name in files:
            file = os.path.join(root, name)
            print >> sys.stderr, "Processing " + file + "..."
            if file.endswith("." + input_ext):
                input_files.append(file)
            if file.endswith("." + output_ext):
                output_files.append(file)
    
    if len(input_files) != len(output_files):
        print >> sys.stderr, "# of input files != # of output files"
        print >> sys.stderr, "Abort"
        exit(-1)

    input_files.sort()
    output_files.sort()

    for i in range(len(input_files)):
        print "# " + input_files[i] + " " + output_files[i] + " " + str(options.timelimit)
